/**
 * 奖励条款规则 编辑页
 *
 * 作者 zjb
 * 日期 2024-08-30 09:51:15
 */
layui.use(['jquery', 'febs', 'form', 'validate', 'laydate','util'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        util = layui.util,
        laydate = layui.laydate,
        $view = $('#incentiveRewardClauseRule-edit'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initDate();
    initFormValue();

    function initFormValue() {
        if (incentiveRewardClauseRuleData) {
            form.val("incentiveRewardClauseRule-edit-form", {
                "clauseRuleId": incentiveRewardClauseRuleData.clauseRuleId,
                "tenantId": incentiveRewardClauseRuleData.tenantId,
                "clauseId": incentiveRewardClauseRuleData.clauseId,
                "clauseNo": incentiveRewardClauseRuleData.clauseNo,
                "clauseLevel": incentiveRewardClauseRuleData.clauseLevel,
                "referenceMoney": incentiveRewardClauseRuleData.referenceMoney,
                "examineScore": incentiveRewardClauseRuleData.examineScore,
                "clauseContent": incentiveRewardClauseRuleData.clauseContent,
                "executeDate": incentiveRewardClauseRuleData.executeDate.substring(0,10),
                "status": incentiveRewardClauseRuleData.status,
            });
            $('#clauseName').text(incentiveRewardClauseRuleData.clauseName)
        } else {
            form.val("incentiveRewardClauseRule-edit-form", {
                "tenantId": POPUP_DATA.tenantId,
                "clauseId": POPUP_DATA.clauseId,
            });
            $('#clauseName').text(POPUP_DATA.clauseName)
        }
    }

    form.on('submit(incentiveRewardClauseRule-edit-form-submit)', function (data) {
        if (data.field.status == "on") {
            data.field.status = '1';
        } else {
            data.field.status = '0';
        }
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        febs.modal.confirm('保存', '确定保存奖励信息？', function () {
            if (data.clauseRuleId && data.clauseRuleId.length > 0) {
                febs.postArray(ctx + 'incentiveRewardClauseRule/update', data, function () {
                    layer.closeAll();
                    febs.alert.success('修改成功');
                    $('#febs-incentiveRewardClauseRule').find('#query').trigger('click');
                });
            } else {
                febs.postArray(ctx + 'incentiveRewardClauseRule', data, function () {
                    layer.closeAll();
                    febs.alert.success('新增成功');
                    $('#febs-incentiveRewardClauseRule').find('#query').trigger('click');
                });
            }
        });
    }

    function initDate() {
        //初始化日期控件
        laydate.render({
            elem: '#febs-form-group-date',
            value: new Date(),
            min: util.toDateString(new Date(), "yyyy-MM-dd"),
        })
    }
});